/*
 * Copyright 2008 Carnegie Mellon University
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package edu.cmu.lti.sepia.infra.topic.model;

import java.util.List;

public class Nugget {
	
	private int nuggetId;
	private int topicId;
	private String text;
	private boolean isSimilar;
	private List<Vote> votes;
	
	public Nugget( int nuggetId, int topicId,
		String text, boolean isSimilar ) {
		this.nuggetId = nuggetId;
		this.topicId = topicId;
		this.text = text;
		this.isSimilar = isSimilar;
	}
	
	public double getWeight() {
	  int yes = getVitalCount();
	  int no = getNonVitalCount(); 
    if ( yes > 0 && (yes + no) > 0) {
      return (double) yes / (double) (yes + no);
    } else {
      return 0D;
    }
	}
	
	public int getVitalCount() {
	  int counter = 0;
	  if ( votes!=null ) {
      for ( Vote v : votes ) {
        if ( v.isVoted() ) {
          counter++;
        } 
      }
    }
	  return counter;
	}
	

  public int getNonVitalCount() {
    int counter = 0;
    if ( votes!=null ) {
      for ( Vote v : votes ) {
        if ( !v.isVoted() ) {
          counter++;
        } 
      }
    }
    return counter;
  }
	
	/**
	 * @return the nuggetId
	 */
	public int getNuggetId() {
		return nuggetId;
	}
	/**
	 * @return the topicId
	 */
	public int getTopicId() {
		return topicId;
	}
	/**
	 * @return the text
	 */
	public String getText() {
		return text;
	}
	/**
	 * @return the isSimilar
	 */
	public boolean isSimilar() {
		return isSimilar;
	}
	/**
	 * @return the votes
	 */
	public List<Vote> getVotes() {
		return votes;
	}

	/**
	 * @param votes the votes to set
	 */
	public void setVotes(List<Vote> votes) {
		this.votes = votes;
	}	
	
	/**
   * @param topicId the topicId to set
   */
  public void setTopicId(int topicId) {
    this.topicId = topicId;
  }

  @Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append( "nuggetId = "+nuggetId+", " );
		sb.append( "topicId = "+topicId+", " );
		sb.append( "text = "+text+", " );
		sb.append( "isSimilar = "+isSimilar );
		return sb.toString();
	}
}
